<template>
    <div id="AsnDetailList">
        <v-tableTitle :btnConfig="btnConfig"
                      :tableSelectData="selectData"
                      @backList="backList"
                      @del="del"
                      @newCreate="newCreate"></v-tableTitle>
        <div class="detail">
            <component :data="{detailData,argument}"
                       :is="currentComponent"></component>
        </div>
    </div>

</template>

<script>
import tableTitle from "commons/TableTitle";
import navMenu from "commons/NavMenu";
import baseMixin from "@/mixins/BaseMixin";
import config from "../Config"

export default {
    name: "DetailList",
    mixins: [baseMixin, config],
    data() {
        return {
            newFlag: false,
            detailsNew: false,
            detailsFlag: false,
            argument: {},
            detailData: {
                transferlinenumber: "00001",
                fromsku: "",
                fromloc: "",
                fromlot: "",
                fromid: "",
                fromqty: "",
                tosku: "",
                toloc: "",
                tolot: "",
                toid: "",
                toqty: "",
                lottable01: "",
                lottable02: "",
                lottable03: "",
                lottable04: null,
                lottable05: null,
                lottable06: "",
                lottable07: "",
                lottable08: "",
                lottable09: "",
                lottable10: "",
            },
            selectData: [],
            detailNav: "1",
            componentConfig: [
                {
                    name: "Table",
                    label: "table",
                    component: () => import('./page/Table.vue')
                },
                {
                    name: "GatherDetailDetail",
                    label: this.$t('common.detail'),
                    component: () => import('./page/particularsDetail.vue')
                },
            ]
        }
    },
    computed: {
        btnConfig() {
            if (this.detailNav == 1) {
              if (this.argument.status == '9') {
                return []
              }else{
                return [
                  {label: this.$t('common.create'), certigier: !this.btnPermNameList.includes('WM06020705'), invalid: "newCreate"},
                  {label: this.$t('common.delete'), certigier: !this.btnPermNameList.includes('WM06020706'), disabled: true, invalid: "del"},
                ]
              }
            } else if (this.$store.state.newFlag) {
                return []
            } else {
                return [
                    {label: this.$t('common.return'), certigier: !this.btnPermNameList.includes('WM06020707'), invalid: "backList"},
                ]
            }
        },
        currentComponent() {
            return this.componentConfig[this.detailNav - 1].component;
        }
    },
    methods: {
        //删除数据
        async del(data) {
            try {
                let res = await this.$api.post(`/deleteRtxTransferDetail`, data);
                
                    this.$message.success(res.returnMgr);
                    this.$children[1].getTableData(1, {})
                
            } catch (e) {
                this.$message.error(e);
            } finally {
                this.$children[1].$refs.table.delSelectData(data);
            }
        },
        //选中的数据
        setSelectData(data) {
            this.selectData = data;
        },
        //返回试图
        backList() {
            this.detailNav = "1";
            this.detailsFlag = false;
            this.detailsNew = false;
        },
        //新建
        async newCreate() {
            try {
                let res = await this.$api.get(`/queryRtxTransferdetailMaxLine/${this.argument.transferkey}`);
                
                    this.detailData = {
                        transferlinenumber: res.bean,
                        fromsku: "",
                        fromloc: "",
                        fromlot: "",
                        fromid: "",
                        fromqty: "",
                        tosku: "",
                        toloc: "",
                        tolot: "",
                        toid: "",
                        toqty: "",
                        lottable01: "",
                        lottable02: "",
                        lottable03: "",
                        lottable04: null,
                        lottable05: null,
                        lottable06: "",
                        lottable07: "",
                        lottable08: "",
                        lottable09: "",
                        lottable10: "",
                    };
                    this.detailsFlag = true;
                    this.detailsNew = true;
                    this.detailNav = "2";
                
            } catch (e) {
                this.$message.error(e);
            }

        },
        async setdialog(data) {
            try {
                let res = await this.$api.post(`/queryRtxTransferDetailByKey`, {
                    transferkey: this.argument.transferkey,
                    transferlinenumber: data.transferlinenumber
                });
                
                    this.detailData = res.bean;
                    this.detailsFlag = true;
                    this.detailNav = "2";
                
            } catch (e) {
                this.$message.error(e);
            }
        },
    },
    async mounted() {
        // 
        this.newFlag = this.$store.state.newFlag;
        if (Object.keys(this.$store.state.skip).length !== 0) {
            let data = this.$store.state.skip;
            this.argument = data.routeData;
            this.detailData = data.detailList;
            this.detailNav = data.detailListNav;
            this.detailsFlag = data.detailListFlag;
        } else if (this.newFlag) {
            this.detailsFlag = true;
            this.detailsNew = true
            this.newCreate()
        } else {
            this.argument = this.$store.state.routeData;
        }

    },
    components: {
        "v-tableTitle": tableTitle,
        "v-navMenu": navMenu,
    },
    watch: {
        selectData(data) {
            // if (this.permissionStatus) {
            //     if (data.length > 0) {
            //         this.deleteDetailStatus = false;
            //     } else {
            //         this.deleteDetailStatus = true;
            //     }
            // }
        }
    }
}
</script>

<style>
</style>
